package com.charity.mapper;

import com.charity.pojo.Donation;
import com.charity.pojo.Entry;
import org.apache.ibatis.annotations.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Mapper
public interface EntryMapper {

    @Select("SELECT * from entryd where state='通过'")
    List<Entry> entryByFbu();

    @Select("SELECT * from entryd where id=#{id}")
    Entry entryById(Long id);

    @Insert("insert into entryd(id, entryName, recipientId, introduction, type, pic, targetAmount, beginDate, endDate, account, state) " +
            "values(#{id}, #{entryName}, #{recipientId}, #{introduction}, #{type}, #{pic}, #{targetAmount}, #{beginDate}, #{endDate}, #{account}, #{state})")
    Integer addEntry(Long id, String entryName, Long recipientId, String introduction, String type, String pic, Long targetAmount, String beginDate, String endDate,
                     String account, String state);

    @Select("SELECT id from entryd order BY targetAmount-collectAmount desc LIMIT 1")
   Long entryByType();

    @Update("UPDATE entryd set collectAmount=collectAmount+#{mount} where id=#{id}")
    Integer updEntryCol(Long id, Long mount);

    @Select("SELECT * from entryd where recipientId=#{recipientId}")
    List<Entry> entryByRecId(Long recipientId);

    @Update("UPDATE entryd set introduction=#{introduction},type=#{type},pic=#{pic},targetAmount=#{targetAmount},state=#{state},reviewer=#{reviewer} where id=#{id}")
    Integer updEntry(Long id, String introduction, String type, String pic, Long targetAmount, String state, String reviewer);

    @Update("UPDATE entryd set stateM=#{stateM},account=#{account} where id=#{id}")
    Integer updEntryBySQ(Long id,String account, String stateM);

    @Update("UPDATE entryd set whereAbouts=#{whereAbouts},picM=#{picM} where id=#{id}")
    Integer updEntryByBC(Long id, String whereAbouts, String picM);

    @Select("SELECT * from entryd where state='审核中'")
    List<Entry> selBySH();

    @Update("UPDATE entryd set state=#{state},reviewer=#{reviewer} where id=#{id}")
    Integer updSh(Long id, String state, String reviewer);

    @Select("SELECT * from entryd where state='不通过'")
    List<Entry> selWTG();

    @Delete("delete from entryd where id=#{id}")
    Integer delD(Long id);

    @Select("select * from entryd where collectAmount>=targetAmount")
    List<Entry> selJQ();

    @Update("UPDATE entryd set state=#{state},issuedAmount=collectAmount where id=#{id}")
    Integer upWJ(Long id, String state);

    @Select("select * from entryd where stateM='审核中'")
    List<Entry> selFSQ();

    @Update("UPDATE entryd set state='结束',issuedAmount=collectAmount where id=#{id}")
    Integer upZJ(Long id);

    @Select("select account from entryd where id=#{id}")
    String selAC(Long id);

}
